<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<link rel="STYLESHEET" href="lib.css" type='text/css' />
<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
<link rel='start' href='../index.html' title='Python documentation Index' />
<link rel="first" href="lib.html" title='Python library Reference' />
<link rel='contents' href='contents.html' title="Contents" />
<link rel='index' href='genindex.html' title='Index' />
<link rel='last' href='about.html' title='About this document...' />
<link rel='help' href='about.html' title='About this document...' />
<link rel="next" href="os-newstreams.html" />
<link rel="prev" href="module-os.html" />
<link rel="parent" href="module-os.html" />
<link rel="next" href="os-newstreams.html" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name='aesop' content='information' />
<title>14.1.1 Process Parameters </title>
</head>
<body>
<div class="navigation">
<div id='top-navigation-panel' xml:id='top-navigation-panel'>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="14.1 os  "
  href="module-os.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></a></td>
<td class='online-navigation'><a rel="parent" title="14.1 os  "
  href="module-os.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up one Level' width='32' /></a></td>
<td class='online-navigation'><a rel="next" title="14.1.2 file Object Creation"
  href="os-newstreams.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></a></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></a></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></a></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="module-os.html">14.1 os  </a>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="module-os.html">14.1 os  </a>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="os-newstreams.html">14.1.2 File Object Creation</a>
</div>
<hr /></div>
</div>
<!--End of Navigation Panel-->

<h2><a name="SECTION0016110000000000000000"></a><a name="os-procinfo"></a>
<br>
14.1.1 Process Parameters 
</h2>

<p>
These functions and data items provide information and operate on the
current process and user.

<p>
<dl><dt><b><tt id='l2h-2581' xml:id='l2h-2581'>environ</tt></b></dt>
<dd>
A mapping object representing the string environment. For example,
<code>environ['HOME']</code> is the pathname of your home directory (on some
platforms), and is equivalent to <code>getenv("HOME")</code> in C.

<p>
This mapping is captured the first time the <tt class="module">os</tt> module is
imported, typically during Python startup as part of processing
<span class="file">site.py</span>.  Changes to the environment made after this time are
not reflected in <code>os.environ</code>, except for changes made by modifying
<code>os.environ</code> directly.

<p>
If the platform supports the <tt class="function">putenv()</tt> function, this
mapping may be used to modify the environment as well as query the
environment.  <tt class="function">putenv()</tt> will be called automatically when
the mapping is modified.
<span class="note"><b class="label">Note:</b>
Calling <tt class="function">putenv()</tt> directly does not change
<code>os.environ</code>, so it's better to modify <code>os.environ</code>.</span>
<span class="note"><b class="label">Note:</b>
On some platforms, including FreeBSD and Mac OS X, setting
<code>environ</code> may cause memory leaks.  Refer to the system documentation
for <tt class="cfunction">putenv()</tt>.</span>

<p>
If <tt class="function">putenv()</tt> is not provided, a modified copy of this mapping 
may be passed to the appropriate process-creation functions to cause 
child processes to use a modified environment.

<p>
If the platform supports the <tt class="function">unsetenv()</tt> function, you can 
delete items in this mapping to unset environment variables.
<tt class="function">unsetenv()</tt> will be called automatically when an item is
deleted from <code>os.environ</code>.

<p>
</dd></dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt class="function">chdir</tt></b>(</nobr></td>
  <td><var>path</var>)</td></tr></table></dt>
<dd>
<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt class="function">fchdir</tt></b>(</nobr></td>
  <td><var>fd</var>)</td></tr></table></dt>
<dd><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt class="function">getcwd</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>These functions are described in ``Files and Directories'' (section
<a href="os-file-dir.html#os-file-dir">14.1.4</a>).
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2582' xml:id='l2h-2582' class="function">ctermid</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
Return the filename corresponding to the controlling terminal of the
process.
Availability: <span class="Unix">Unix</span>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2583' xml:id='l2h-2583' class="function">getegid</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
Return the effective group id of the current process.  This
corresponds to the `set id' bit on the file being executed in the
current process.
Availability: <span class="Unix">Unix</span>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2584' xml:id='l2h-2584' class="function">geteuid</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
<a id='l2h-2614' xml:id='l2h-2614'></a>
Return the current process' effective user id.
Availability: <span class="Unix">Unix</span>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2585' xml:id='l2h-2585' class="function">getgid</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
<a id='l2h-2615' xml:id='l2h-2615'></a>
Return the real group id of the current process.
Availability: <span class="Unix">Unix</span>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2586' xml:id='l2h-2586' class="function">getgroups</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
Return list of supplemental group ids associated with the current
process.
Availability: <span class="Unix">Unix</span>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2587' xml:id='l2h-2587' class="function">getlogin</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
Return the name of the user logged in on the controlling terminal of
the process.  For most purposes, it is more useful to use the
environment variable <a class="envvar" id='l2h-2616' xml:id='l2h-2616'>LOGNAME</a> to find out who the user is,
or <code>pwd.getpwuid(os.getuid())[0]</code> to get the login name
of the currently effective user ID.
Availability: <span class="Unix">Unix</span>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2588' xml:id='l2h-2588' class="function">getpgid</tt></b>(</nobr></td>
  <td><var>pid</var>)</td></tr></table></dt>
<dd>
Return the process group id of the process with process id <var>pid</var>.
If <var>pid</var> is 0, the process group id of the current process is
returned. Availability: <span class="Unix">Unix</span>.

<span class="versionnote">New in version 2.3.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2589' xml:id='l2h-2589' class="function">getpgrp</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
<a id='l2h-2617' xml:id='l2h-2617'></a>
Return the id of the current process group.
Availability: <span class="Unix">Unix</span>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2590' xml:id='l2h-2590' class="function">getpid</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
<a id='l2h-2618' xml:id='l2h-2618'></a>
Return the current process id.
Availability: <span class="Unix">Unix</span>, Windows.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2591' xml:id='l2h-2591' class="function">getppid</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
<a id='l2h-2619' xml:id='l2h-2619'></a>
Return the parent's process id.
Availability: <span class="Unix">Unix</span>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2592' xml:id='l2h-2592' class="function">getuid</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
<a id='l2h-2620' xml:id='l2h-2620'></a>
Return the current process' user id.
Availability: <span class="Unix">Unix</span>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2593' xml:id='l2h-2593' class="function">getenv</tt></b>(</nobr></td>
  <td><var>varname</var><big>[</big><var>, value</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Return the value of the environment variable <var>varname</var> if it
exists, or <var>value</var> if it doesn't.  <var>value</var> defaults to
<code>None</code>.
Availability: most flavors of <span class="Unix">Unix</span>, Windows.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2594' xml:id='l2h-2594' class="function">putenv</tt></b>(</nobr></td>
  <td><var>varname, value</var>)</td></tr></table></dt>
<dd>
<a id='l2h-2621' xml:id='l2h-2621'></a>
Set the environment variable named <var>varname</var> to the string
<var>value</var>.  Such changes to the environment affect subprocesses
started with <tt class="function">os.system()</tt>, <tt class="function">popen()</tt> or
<tt class="function">fork()</tt> and <tt class="function">execv()</tt>.
Availability: most flavors of <span class="Unix">Unix</span>, Windows.

<p>
<span class="note"><b class="label">Note:</b>
On some platforms, including FreeBSD and Mac OS X,
setting <code>environ</code> may cause memory leaks.
Refer to the system documentation for putenv.</span>

<p>
When <tt class="function">putenv()</tt> is
supported, assignments to items in <code>os.environ</code> are automatically
translated into corresponding calls to <tt class="function">putenv()</tt>; however,
calls to <tt class="function">putenv()</tt> don't update <code>os.environ</code>, so it is
actually preferable to assign to items of <code>os.environ</code>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2595' xml:id='l2h-2595' class="function">setegid</tt></b>(</nobr></td>
  <td><var>egid</var>)</td></tr></table></dt>
<dd>
Set the current process's effective group id.
Availability: <span class="Unix">Unix</span>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2596' xml:id='l2h-2596' class="function">seteuid</tt></b>(</nobr></td>
  <td><var>euid</var>)</td></tr></table></dt>
<dd>
Set the current process's effective user id.
Availability: <span class="Unix">Unix</span>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2597' xml:id='l2h-2597' class="function">setgid</tt></b>(</nobr></td>
  <td><var>gid</var>)</td></tr></table></dt>
<dd>
Set the current process' group id.
Availability: <span class="Unix">Unix</span>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2598' xml:id='l2h-2598' class="function">setgroups</tt></b>(</nobr></td>
  <td><var>groups</var>)</td></tr></table></dt>
<dd>
Set the list of supplemental group ids associated with the current
process to <var>groups</var>. <var>groups</var> must be a sequence, and each
element must be an integer identifying a group. This operation is
typical available only to the superuser.
Availability: <span class="Unix">Unix</span>.

<span class="versionnote">New in version 2.2.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2599' xml:id='l2h-2599' class="function">setpgrp</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
Calls the system call <tt class="cfunction">setpgrp()</tt> or <tt class="cfunction">setpgrp(0,
0)</tt> depending on which version is implemented (if any).  See the
<span class="Unix">Unix</span> manual for the semantics.
Availability: <span class="Unix">Unix</span>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2600' xml:id='l2h-2600' class="function">setpgid</tt></b>(</nobr></td>
  <td><var>pid, pgrp</var>)</td></tr></table></dt>
<dd> Calls the system call
<tt class="cfunction">setpgid()</tt> to set the process group id of the process with
id <var>pid</var> to the process group with id <var>pgrp</var>.  See the <span class="Unix">Unix</span>
manual for the semantics.
Availability: <span class="Unix">Unix</span>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2601' xml:id='l2h-2601' class="function">setreuid</tt></b>(</nobr></td>
  <td><var>ruid, euid</var>)</td></tr></table></dt>
<dd>
Set the current process's real and effective user ids.
Availability: <span class="Unix">Unix</span>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2602' xml:id='l2h-2602' class="function">setregid</tt></b>(</nobr></td>
  <td><var>rgid, egid</var>)</td></tr></table></dt>
<dd>
Set the current process's real and effective group ids.
Availability: <span class="Unix">Unix</span>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2603' xml:id='l2h-2603' class="function">getsid</tt></b>(</nobr></td>
  <td><var>pid</var>)</td></tr></table></dt>
<dd>
Calls the system call <tt class="cfunction">getsid()</tt>.  See the <span class="Unix">Unix</span> manual
for the semantics.
Availability: <span class="Unix">Unix</span>. 
<span class="versionnote">New in version 2.4.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2604' xml:id='l2h-2604' class="function">setsid</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
Calls the system call <tt class="cfunction">setsid()</tt>.  See the <span class="Unix">Unix</span> manual
for the semantics.
Availability: <span class="Unix">Unix</span>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2605' xml:id='l2h-2605' class="function">setuid</tt></b>(</nobr></td>
  <td><var>uid</var>)</td></tr></table></dt>
<dd>
<a id='l2h-2622' xml:id='l2h-2622'></a>
Set the current process' user id.
Availability: <span class="Unix">Unix</span>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2606' xml:id='l2h-2606' class="function">strerror</tt></b>(</nobr></td>
  <td><var>code</var>)</td></tr></table></dt>
<dd>
Return the error message corresponding to the error code in
<var>code</var>.
Availability: <span class="Unix">Unix</span>, Windows.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2607' xml:id='l2h-2607' class="function">umask</tt></b>(</nobr></td>
  <td><var>mask</var>)</td></tr></table></dt>
<dd>
Set the current numeric umask and returns the previous umask.
Availability: <span class="Unix">Unix</span>, Windows.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2608' xml:id='l2h-2608' class="function">uname</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
Return a 5-tuple containing information identifying the current
operating system.  The tuple contains 5 strings:
<code>(<var>sysname</var>, <var>nodename</var>, <var>release</var>, <var>version</var>,
<var>machine</var>)</code>.  Some systems truncate the nodename to 8
characters or to the leading component; a better way to get the
hostname is <tt class="function">socket.gethostname()</tt>
<a id='l2h-2610' xml:id='l2h-2610'></a>or even
<a id='l2h-2612' xml:id='l2h-2612'></a><code>socket.gethostbyaddr(socket.gethostname())</code>.
Availability: recent flavors of <span class="Unix">Unix</span>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2613' xml:id='l2h-2613' class="function">unsetenv</tt></b>(</nobr></td>
  <td><var>varname</var>)</td></tr></table></dt>
<dd>
<a id='l2h-2623' xml:id='l2h-2623'></a>
Unset (delete) the environment variable named <var>varname</var>. Such
changes to the environment affect subprocesses started with
<tt class="function">os.system()</tt>, <tt class="function">popen()</tt> or <tt class="function">fork()</tt> and
<tt class="function">execv()</tt>. Availability: most flavors of <span class="Unix">Unix</span>, Windows.

<p>
When <tt class="function">unsetenv()</tt> is
supported, deletion of items in <code>os.environ</code> is automatically
translated into a corresponding call to <tt class="function">unsetenv()</tt>; however,
calls to <tt class="function">unsetenv()</tt> don't update <code>os.environ</code>, so it is
actually preferable to delete items of <code>os.environ</code>.
</dl>

<p>

<div class="navigation">
<div class='online-navigation'>
<p></p><hr />
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="14.1 os  "
  href="module-os.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></a></td>
<td class='online-navigation'><a rel="parent" title="14.1 os  "
  href="module-os.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up one Level' width='32' /></a></td>
<td class='online-navigation'><a rel="next" title="14.1.2 file Object Creation"
  href="os-newstreams.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></a></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></a></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></a></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="module-os.html">14.1 os  </a>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="module-os.html">14.1 os  </a>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="os-newstreams.html">14.1.2 File Object Creation</a>
</div>
</div>
<hr />
<span class="release-info">Release 2.5.1, documentation updated on 18th April, 2007.</span>
</div>
<!--End of Navigation Panel-->
<address>
See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
</address>
</body>
</html>
